<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-inFo
                :disabled="disableSubmit"
                :msg="dataId"
                v-decorator="['yongHuBiaoShi', validatorRules.yongHuBiaoShi]"
                :trigger-change="true"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="测量时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date
                :disabled="disableSubmit"
                placeholder="请选择测量时间"
                v-decorator="['ceLiangShiJian', validatorRules.ceLiangShiJian]"
                :trigger-change="true"
                style="width: 100%"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="体温值" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input
                :disabled="disableSubmit"
                v-decorator="['tiWenZhi', validatorRules.tiWenZhi]"
                placeholder="请输入体温值"
              ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="测温位置" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag
                :disabled="disableSubmit"
                type="list"
                v-decorator="['ceWenWeiZhi', validatorRules.ceWenWeiZhi]"
                :trigger-change="true"
                dictCode="gkak_cwwz"
                placeholder="请选择测温位置"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="分析结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag
                type="list"
                :disabled="true"
                v-decorator="['fenXiJieGuo', validatorRules.fenXiJieGuo]"
                :trigger-change="true"
                dictCode="gkak_fxjg"
                placeholder="请选择分析结果"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="参考意见" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input
                :disabled="disableSubmit"
                v-decorator="['canKaoYiJian', validatorRules.canKaoYiJian]"
                placeholder="请输入参考意见"
              ></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-search-select-tag
                :disabled="disableSubmit"
                v-decorator="['sheBeiMingCheng', validatorRules.sheBeiMingCheng]"
                dict="gkak_sb_she_bei_xin_xi,she_bei_ming_cheng,she_bei_xu_lie_hao"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="设备序列号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input
                :disabled="disableSubmit"
                v-decorator="['sheBeiXuLieHao', validatorRules.sheBeiXuLieHao]"
                placeholder="请输入设备序列号"
              ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea
                :disabled="disableSubmit"
                v-decorator="['beiZhu', validatorRules.beiZhu]"
                rows="4"
                placeholder="请输入备注"
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import { validateDuplicateValue } from '@/utils/util'
import JDate from '@/components/jeecg/JDate'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import JSelectInFo from '@/components/jeecgbiz/JSelectInFo'

export default {
  name: 'GkakJkTiWenCaiJiModal',
  components: {
    JDate,
    JDictSelectTag,
    JSearchSelectTag,
    JSelectInFo
  },
  data() {
    return {
      form: this.$form.createForm(this),
      disableSubmit: false,
      dataId: {},

      title: '操作',
      width: 800,
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        xingMing: { rules: [{ required: true, message: '请输入姓名!' }] },
        ceLiangShiJian: { rules: [{ required: true, message: '请输入测量时间!' }] },
        tiWenZhi: { rules: [{ required: true, message: '请输入体温值!' }] },
        ceWenWeiZhi: { rules: [{ required: true, message: '请选择测温位置 !' }] },
        fenXiJieGuo: { rules: [] },
        canKaoYiJian: { rules: [{ required: true, message: '请输入参考意见!' }] },
        sheBeiMingCheng: { rules: [] },
        sheBeiXuLieHao: { rules: [] },
        beiZhu: { rules: [] }
      },
      url: {
        add: '/gkakJkTiWenCaiJi/add',
        edit: '/gkakJkTiWenCaiJi/edit'
      }
    }
  },
  created() {},
  methods: {
    inFoId(record) {
      debugger
      this.$nextTick(() => {
        this.dataId = {
          id: record.yongHuBiaoShi,
          name: record.xingMing
        }
      })
    },
    add() {
      this.edit({})
    },

    edit(record) {
      this.$nextTick(() => {
        this.dataId = {
          id: record.yongHuBiaoShi,
          name: record.xingMing
        }
      })
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(
          pick(
            this.model,
            'xingMing',
            'ceLiangShiJian',
            'tiWenZhi',
            'ceWenWeiZhi',
            'fenXiJieGuo',
            'canKaoYiJian',
            'sheBeiMingCheng',
            'sheBeiXuLieHao',
            'beiZhu',
            'yongHuBiaoShi'
          )
        )
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model, values)
          console.log('表单提交数据', formData)
          httpAction(httpurl, formData, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    popupCallback(row) {
      this.form.setFieldsValue(
        pick(
          row,
          'xingMing',
          'ceLiangShiJian',
          'tiWenZhi',
          'ceWenWeiZhi',
          'fenXiJieGuo',
          'canKaoYiJian',
          'sheBeiMingCheng',
          'sheBeiXuLieHao',
          'beiZhu',
          'yongHuBiaoShi'
        )
      )
    }
  }
}
</script>
